package edu.suda.xsap.service.impl;

import edu.suda.xsap.dto.EmployeeDto;
import edu.suda.xsap.dto.convert.EmployeeConvert;
import edu.suda.xsap.mapper.EmployeeMapper;
import edu.suda.xsap.service.EmployeeService;
import edu.suda.xsapadminutils.common.Result;
import edu.suda.xsapadminvo.EmployeeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    private EmployeeConvert employeeConvert;

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public Result save(EmployeeVO employeeVO) {
        employeeMapper.save(employeeVO);
        return Result.success("新增成功");
    }

    @Override
    public List<EmployeeDto> findAll() {
        return employeeConvert.toDtoList(employeeMapper.findAll());
    }

    @Override
    public Result delete(EmployeeVO employeeVO) {
        employeeMapper.delete(employeeVO);
        return Result.success("删除成功");
    }

    @Override
    public Result update(EmployeeVO employeeVO) {
        employeeMapper.update(employeeVO);
        return Result.success("更新成功");
    }

    @Override
    public Integer findByName(String name) {
        return employeeMapper.findByName(name);
    }


}
